using System;
using System.Collections;
using System.Collections.Generic;
using Main.Details;
using Main.Inventory;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using ZSW.Framework;
using ZSW.Framework.UIElement;

namespace Main.UI
{
    public class UI_Trade : ZSWF_BaseUIElement
    {
        public Image Icon;
        public TMP_Text itemName;
        public TMP_InputField tradeAmount;
        public Button submitBtn;
        public Button cancelBtn;

        private ItemDetails item;
        private bool isSellTread;

        private void Awake()
        {
            cancelBtn.onClick.AddListener(CancelTrade);
            submitBtn.onClick.AddListener(SubmitTrade);
            Hide();
        }

        private void SubmitTrade()
        {
            var amount = int.Parse(tradeAmount.text);

            ZSWF_IOCContainer.Get<InventoryManager>().TradeMoney(item, amount, isSellTread);

            Hide();
        }

        private void CancelTrade()
        {
            Hide();
        }

        public void SetupTradeUI(ItemDetails item, bool isSell)
        {
            this.item = item;
            Icon.sprite = item.ItemIcon;
            itemName.text = item.ItemName + "\n输入要交易的数量";
            isSellTread = isSell;
            tradeAmount.text = string.Empty;
        }
    }
}